// 该文件需要向外暴露一个函数,该函数可以发送请求

import config from './config.js';

export default function (url, data={}, method="GET") {
  return new Promise((resolve,reject) => {
    // 发送请求,是同步发送,异步接收
    wx.request({
      url: config.mpHost + url,
      data,
      method,
      header:{
        Cookie:wx.getStorageSync('cookie')
      },
      success: (res) => {
        if (data._isLogin) {
          const cookie = res.cookies.find((item) => {
            return item.startsWith('MUSIC_U')
          })

          wx.setStorage({
            key: "cookie",
            data: cookie
          })
        }
        resolve(res.data)
      }
    })
  })
  // return result;
}